<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>账单列表</title>
<style type="text/css">
td {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: gray;
	/* background-color: black; */
	table-layout: fixed
}

th {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: orange;
	/* background-color: black; */
	table-layout: fixed
		/* background-image: url("D://我的文档//图片收藏//美女//psbCACFYQKB.jpg"); */
}

.id {
	font-size: 15px;
	width: 60px;
	text-align: center;
	color: aqua;
	background-color: black;
}

.t {
	color: green;
	text-decoration: line-through;
}
</style>
<script type="text/javascript">
	function up(n, ye) {
		location.href = "BillRead?b=b&Update=" + n + "&num=" + ye;
	}

	//账单添加
	function add(){
		var name = document.getElementById("iname").value;
		var price = document.getElementById("iprice").value;
		var pay = document.getElementById("ipay").value;
		var unit = document.getElementById("iunit").value;
		var num = document.getElementById("inumber").value;
		var description = document.getElementById("idescription").value;
		var regu = "^([0-9]*[.0-9])$"; // 小数测试
		var re = new RegExp(regu);
		if (name.length == 0 || price.length == 0
				|| pay.length == 0 || unit.length == 0
				|| num.length == 0 || description.length == 0) {
			alert("全部为为必填项!");
		}else if(price.search(re) ==-1||price=="."){
			alert("金额为非法数字，请重新输入！");
		}  else {
			if (confirm("确定要添加账单吗？") == true) {
				submit();
			}
		}
		return false;
	}
	function remove(i,n) {
		if (confirm("你确信要删除账单"+n+"吗？") == true) {
			location.href = "BillRemove?Remove=" + i;
		} else {
			alert("取消");
		}
	}
	function adds(n,y) {
		if (n != 3) {
			location.href = "BillRead?add=2&num="+y;
		} else {
			location.href = "BillRead?num="+y;
		}

	}
	function newye(ye) {
		location.href = "BillRead?num="+ye+"&b=b";
	}
	function tiao(ye, yenum) {
		if (ye<1||ye>yenum||ye=="请输入") {
			alert("该页不存在哦");
		} else {
			newye(ye);
		}
	}
	//账单更新
	function update() {
		//alert(document.getElementById("id").innerHTML);
		var name = document.getElementById("name").value;
		var price = document.getElementById("price").value;
		var pay = document.getElementById("pay").value;
		var unit = document.getElementById("unit").value;
		var number = document.getElementById("number").value;
		var description = document.getElementById("description").value;
		if (name.length == 0 || price.length == 0
				|| pay.length == 0 || unit.length == 0
				|| number.length == 0 || description.length == 0) {
			alert("全部为为必填项!");
		} else {
			if (confirm("确定要更新账单吗？") == true) {
				submit();
			}
		}
		return false;
	}
	function no() {
		location.href = "BillRead";
	}
	function showTime(){
        var tDate = new Date();
        var tseconds = tDate.getSeconds();
        if (tseconds < 10)
            tseconds = '0' + tseconds;
        var timeStr1 = tDate.getFullYear()+"-"+(tDate.getMonth()+1)+"-"+tDate.getDate()+"-";
        var timeStr2 = tDate.getHours() + ':' + tDate.getMinutes() + ':' + tseconds;
        document.getElementById('time1').innerHTML = timeStr1;
        document.getElementById('time2').innerHTML = timeStr2;
        setTimeout(showTime, 1000);
    } 
</script>
</head>
<body bgcolor="#000000" onload="showTime()">
	<c:choose>
		<c:when test="${loginname!=null}">
			<div class="menu" align="center" style="color: green;">
				<form method="post" action="BillRead">
					商品名称：<input type="text" name="productName" class="input-text"
						value="<c:out value="${productName}" default="" />" />&nbsp;&nbsp;&nbsp;&nbsp;
					是否付款：<select name="payStatus">
						<option value="">请选择</option>
						<option value="已付款">已付款</option>
						<option value="未付款">未付款</option>
					</select>&nbsp;&nbsp;&nbsp;&nbsp; <input type="submit" name="submit"
						value="组合查询" class="button" /> &nbsp;&nbsp;&nbsp;&nbsp; <input
						type="button" value="增加"
						onclick="adds(<c:out value="${add}" default="2"/>,${num});">
				</form>
				<br>
			</div>
			<form method="post" action="BillUpdate" onsubmit="return update();">
				<c:choose>
					<c:when test="${nulls!=null}">
						</br>
						<div style="color: red; text-align: center;">${nulls}</div>
						</br>
					</c:when>
					<c:otherwise>
						<table cellspacing="1" cellpadding="1" align="center" width="800">
							<tr>
								<th><nobr>账单编号</nobr></th>
								<th><nobr>商品名称</nobr></th>
								<th><nobr>交易单位</nobr></th>
								<th><nobr>商品数量</nobr></th>
								<th><nobr>交易金额</nobr></th>
								<th><nobr>是否付款</nobr></th>
								<th><nobr>供应商名称</nobr></th>
								<th><nobr>商品描述</nobr></th>
								<th><nobr>账单时间</nobr></th>
							</tr>
							<c:forEach var="l" items="${list}" varStatus="varstatus">
								<c:choose>
									<c:when test="${update==l.id}">
										<tr>
											<td><input type="hidden" name="num" value="${num}" /><input
												type="hidden" name="id" value="${l.id}" /><input
												type="hidden" name="b" value="b"></td>
											<td><input type="text" size="4" id="name" name="name"
												value="${l.name}"></td>
											<td><input type="text" id=unit size="4" name="unit"
												value="${l.unit}"></td>
											<td><input type="text" id="number" name="number"
												size="4" value="${l.num}"
												onKeyUp="value=value.replace(/\D/g,'')"></td>
											<td><input type="text" id="price" name="price" size="4"
												value="${l.price}"
												onkeyup="value=value.replace(/[^\d\.]/g,'')"></td>
											<td><select name="pay" id="pay">
													<option value="已付款">已付款</option>
													<option value="未付款">未付款</option>
											</select></td>
											<td><select name="s_name" id="s_name">
													<c:forEach var="sl" items="${slist}" varStatus="varstatus">
														<option value="${sl.id}">${sl.name}</option>
													</c:forEach>
											</select></td>
											<td><input type="text" id="description"
												name="description" size="4" value="${l.description}">
											</td>
											<td>${l.date}</td>
											<td><input type="submit" value="保存"></td>
											<td><input type="button" value="删除"
												onclick="remove(${l.id},'${l.name}');"></td>
										</tr>
									</c:when>
									<c:otherwise>
										<tr>
											<td><nobr>${l.id}</nobr></td>
											<td><nobr>${l.name}</nobr></td>
											<td><nobr>${l.unit}</nobr></td>
											<td><nobr>${l.num}</nobr></td>
											<td><nobr>${l.price}</nobr></td>
											<td><nobr>${l.pay}</nobr></td>
											<td><nobr>${l.s_name}</nobr></td>
											<td><marquee direction="left" onmouseover=this.stop()
													onmouseout=this.start()>${l.description}</marquee></td>
											<td><nobr>${l.date}</nobr></td>
											<td><input type="button" value="修改"
												onclick="up(${l.id},${num});"></td>
											<td><input type="button" value="删除"
												onclick="remove(${l.id},'${l.name}');"></td>
										</tr>
									</c:otherwise>
								</c:choose>
							</c:forEach>
					</c:otherwise>
				</c:choose>
				</table>
			</form>
			<c:if test="${add==3}">
				<form action="BillAdd" method="post" onsubmit="return add();">
					<table align="center" cellspacing="1" cellpadding="1" width="800">
						<tr>
							<td align="center"></td>
							<td align="center"><input type="text" size="4" id="iname"
								name="iname"> <input type="hidden" name="b" value="b">
							</td>
							<td align="center"><input type="text" size="4" id="iunit"
								name="iunit"></td>
							<td align="center"><input type="text" size="4" id="inumber"
								name="inumber" onKeyUp="value=value.replace(/\D/g,'')">
							</td>
							<td align="center"><input type="text" size="4" id="iprice"
								name="iprice" onkeyup="value=value.replace(/[^\d\.]/g,'')">
							</td>
							<td align="center"><select name="ipay" id="ipay">
									<option value="已付款">已付款</option>
									<option value="未付款">未付款</option>
							</select></td>
							<td align="center"><select name="is_name" id="is_name">
									<c:forEach var="sl" items="${slist}" varStatus="varstatus">
										<option value="${sl.id}">${sl.name}</option>
									</c:forEach>
							</select></td>
							<td align="center"><input type="text" size="4"
								id="idescription" name="idescription"></td>
							<td align="center"></td>
							<td align="center"><input type="submit" size="4" value="提交">
							</td>
							<td align="center"><input type="button" size="4" value="不提交"
								onclick="no()"></td>
						</tr>
					</table>
				</form>
			</c:if>
			<c:if test="${error!=null}">
				<br>
				<hr width="600">
				<div align="center" style="color: red;">
					</br>${error}
				</div>
				<br>
			</c:if>
			<hr width="800" align="center">
			<br>
			<table width="300" align="center" cellspacing="1">
				<tr class="3">
					<td>${num}/${yenum}</td>
					<td align="center" valign="middle" class="td"><input
						type="text" id="tiao" size="4"
						onKeyUp="value=value.replace(/\D/g,'')" value="请输入"></td>
					<td align="center" valign="middle" class="td"><input
						type="button" onkeyup="this.value=this.value.replace(/\D/g,'')"
						value="跳转"
						onclick="tiao(document.getElementById('tiao').value,${yenum})">
					</td>
				</tr>
			</table>
			<br>
			<br>
			<table width="600" align="center" cellspacing="1">
				<tr class="3">
					<td align="center" valign="middle" class="td"><input
						type="button" value="首页" onclick="newye(1);"></td>
					<c:choose>
						<c:when test="${num!=1}">
							<td align="center" valign="middle" class="td"><input
								type="button" value="上一页" onclick="newye(${num-1});"></td>
						</c:when>
						<c:otherwise>
							<td align="center" valign="middle" class="t">到头了</td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${num!=yenum}">
							<td align="center" valign="middle" class="td"><input
								type="button" value="下一页" onclick="newye(${num+1});"></td>
						</c:when>
						<c:otherwise>
							<td align="center" valign="middle" class="t">没有了</td>
						</c:otherwise>
					</c:choose>
					<td align="center" valign="middle" class="td"><input
						type="button" value="末页" onclick="newye(${yenum});"></td>
				</tr>
			</table>
		</c:when>
		<c:otherwise>
			<div align="center">
				<a onclick="window.top.location='Login.jsp'<%%>" style="color: red;">非法操作，请到首页登录！</a>
			</div>
		</c:otherwise>
	</c:choose>
	</br>
	</br>
	<hr width="600">
	<div align="center" style="color: green;">CopyRight ©
		2000-2015第一个小小网站 , All Rights Reserved</div>
	</br>
	<div align="center"><div id="time1" align="center" style="color: #0000ff;font-size:18px; display:inline;border-style: double;">
    </div><div id="time2" align="center" style="color: #ff0080;font-size:18px; display:inline;border-style: double;"></div></div>
	</br>
</body>
</html>
